package com.gxa.shop.servlet.address;


import com.alibaba.fastjson.JSON;
import com.gxa.shop.bean.vo.ReginVo;
import com.gxa.shop.commons.r.R;
import com.gxa.shop.dao.address.AddressDao;
import com.gxa.shop.dao.address.impl.AddressDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "SelectAllRegin",value = "/select/allRegin")
public class SelectAllRegin extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        AddressDao addressDao=new AddressDaoImpl();
        List<ReginVo> list=addressDao.selectAllRegin();
        R r;
        r=list!=null?R.ok().addData("list",list):R.error("查询失败");

        String listResult= JSON.toJSONString(r);
        System.out.println(listResult);
        PrintWriter writer=resp.getWriter();
        writer.write(listResult);
        writer.flush();
        writer.close();
    }
}
